<?php
// +----------------------------------------------------------------------
// |ZBPHP[基于ThinkPHP5.1开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2019 http://www.benbenwangluo.com
// +----------------------------------------------------------------------
// | Author 似水星辰 [ 2630481389@qq.com ]
// +----------------------------------------------------------------------
// | 中犇软件 技术六部 出品
// +----------------------------------------------------------------------

namespace app\customer\controller;

/**
 * 客服登录
 * @package app\user\controller
 */
class ChatLogin extends \think\Controller
{
    
    protected  $user_id = null;
    protected function initialize()
    {          
      
    }
 
    /**
     * 登录界面
     * @author 晓风<215628355@qq.com>
     * @return mixed
     */
    public function index()
    {
        $param = input("get.");
        $token = $param["token"] ?? null;
        if(!$token){
            return $this->fetch("error");
        }
        if (!preg_match("/^[a-fA-F0-9]{32}$/", $token)) {
            return $this->fetch("error");
        }
        
        $redis = \app\common\model\Redis::handler();
        $info = $redis->get('CT_'.$token);

        if(!$info){
            return $this->fetch("error");
        }
        $info = json_decode($info,true);
        if(!is_array($info)){
            return $this->fetch("error");
        }        
        if(empty($info["user_id"]) || empty($info["store_id"])){
            return $this->fetch("error");
        }  
        session($token,$info);
        $this->redirect(url('/customer/chat/index') .'?'. http_build_query($param));   
    }
}